{
 "metadata": {
  "name": "",
  "signature": "sha256:3016a3927a62cb87cc724804e08f0c8167625044814a1328072ab02828b4632e"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import numpy as np"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 11
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# https://docs.scipy.org/doc/numpy/user/basics.subclassing.html\n",
      "class custom(np.ndarray): pass"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 12
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "A = np.array([1., 2, 3]).view(custom)\n",
      "A\n",
      "print A.view().reshape([-1, 1])\n",
      "print A"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "[[ 1.]\n",
        " [ 2.]\n",
        " [ 3.]]\n",
        "[ 1.  2.  3.]\n"
       ]
      }
     ],
     "prompt_number": 44
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "np.logical_not(True)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 14,
       "text": [
        "False"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "A = np.eye(3)\n",
      "A.T.flat[:] = np.arange(1, 10)\n",
      "A"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 25,
       "text": [
        "array([[ 1.,  4.,  7.],\n",
        "       [ 2.,  5.,  8.],\n",
        "       [ 3.,  6.,  9.]])"
       ]
      }
     ],
     "prompt_number": 25
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "print A[1, :]\n",
      "\n",
      "print A[2, 1]\n",
      "print A[[1, 0], 2]\n",
      "\n",
      "print A[1::-1, 2]\n",
      "print A[1:0:-1, 2]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "[ 2.  5.  8.]\n",
        "6.0\n",
        "[ 8.  7.]\n",
        "[ 8.  7.]\n",
        "[ 8.]\n"
       ]
      }
     ],
     "prompt_number": 36
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "?np.nditer"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 2
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "a_int = np.array([1, 2])\n",
      "a_fl = np.array([1. ,2])\n",
      "a_str = np.array(['a', 'b'], dtype=str)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 4
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "def info(a):\n",
      "    print (a.dtype, a.dtype.type)\n",
      "info(a_int)\n",
      "info(a_fl)\n",
      "info(a_str)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "(dtype('int64'), <type 'numpy.int64'>)\n",
        "(dtype('float64'), <type 'numpy.float64'>)\n",
        "(dtype('S1'), <type 'numpy.string_'>)\n"
       ]
      }
     ],
     "prompt_number": 6
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# https://stackoverflow.com/questions/22471644/how-do-i-check-if-a-numpy-dtype-is-integral\n",
      "?np.integer"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 7
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "?np.floating"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 8
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "np.issubdtype(a_int.dtype, np.integer)"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 10,
       "text": [
        "True"
       ]
      }
     ],
     "prompt_number": 10
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "a_str"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 11,
       "text": [
        "array(['a', 'b'], \n",
        "      dtype='|S1')"
       ]
      }
     ],
     "prompt_number": 11
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "a_str.shape"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 12,
       "text": [
        "(2,)"
       ]
      }
     ],
     "prompt_number": 12
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "a_str.T"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 13,
       "text": [
        "array(['a', 'b'], \n",
        "      dtype='|S1')"
       ]
      }
     ],
     "prompt_number": 13
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "np.array([a_str]).T"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "metadata": {},
       "output_type": "pyout",
       "prompt_number": 14,
       "text": [
        "array([['a'],\n",
        "       ['b']], \n",
        "      dtype='|S1')"
       ]
      }
     ],
     "prompt_number": 14
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "# https://stackoverflow.com/questions/2936863/python-implementing-slicing-in-getitem\n",
      "class Sliceable(object):\n",
      "\n",
      "    def __getitem__(self, given):\n",
      "        if isinstance(given, slice):\n",
      "            # do your handling for a slice object:\n",
      "            print(\"slice\", given.start, given.stop, given.step)\n",
      "        elif isinstance(given, tuple):\n",
      "            print(\"multidim\", given)\n",
      "        else:\n",
      "            # Do your handling for a plain index\n",
      "            print(\"plain\", given)\n",
      "\n",
      "sliceme = Sliceable()\n",
      "sliceme[1]\n",
      "sliceme[::]\n",
      "sliceme[1:, ::-1]"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "('plain', 1)\n",
        "('slice', None, None, None)\n",
        "('multidim', (slice(1, None, None), slice(None, None, -1)))\n"
       ]
      }
     ],
     "prompt_number": 9
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [],
     "language": "python",
     "metadata": {},
     "outputs": []
    }
   ],
   "metadata": {}
  }
 ]
}